package controllers

import config.MyFile
import javax.inject.Inject
import play.api.mvc.{AbstractController, ControllerComponents}
import utils.Utils

import scala.concurrent.ExecutionContext

class DownloadController @Inject()(cc: ControllerComponents)
                                  (implicit exec: ExecutionContext) extends AbstractController(cc) with MyFile {

  def downloadPage = Action {
    Ok(views.html.download.downloadPage())
  }

  def downloadFile(file: String) = Action { implicit request =>
    Ok.sendFile(s"${Utils.path}/data/$file".toFile).withHeaders(
      //缓存
      CACHE_CONTROL -> "max-age=3600",
      CONTENT_DISPOSITION -> s"attachment; filename=$file",
      CONTENT_TYPE -> "application/x-download"
    )
  }

}
